<?php
// +----------------------------------------------------------------------
// | 云游线路产品开发
// +----------------------------------------------------------------------
// | Author: TongBC <50249101@qq.com>
// +----------------------------------------------------------------------
// | Date  : 2015/02/03
// +----------------------------------------------------------------------
// | table : pft_scenic
// +----------------------------------------------------------------------
use \pft\Prod\Product;
include '/var/www/html/new/d/common/header.html';
include '/var/www/html/new/d/common/left.html';
include '/var/www/html/new/d/common/autoload.php';
include '/var/www/html/new/d/common/prodField.php';

$ptype = strtoupper($_GET['type']);
$saveBtn = '<button class="ui-button ui-button-lblue" id="saveProduct" data-wrap="ticketBox" type="button">保存，返回列表</button>';

$apply_did = $_SESSION['sid'];// 供应商ID

// 身份认证
if($_SESSION['dtype']==6 && $_SESSION['sdtype']!=0) {
    exit('您的上级不是供应商身份，无法发布产品。');
}elseif($_SESSION['dtype']!=0 && $_SESSION['dtype']!=9) {
    exit('您不是供应商身份，无法发布产品。');
}

// 获取子景点信息
$cid = $_REQUEST['id'] + 0;
if($cid>0){
	$scenic = array();
	$sql="select * from pft_scenic where id=$cid limit 1";
	$GLOBALS['le']->query($sql);
	$scenic = $GLOBALS['le']->fetch_assoc();
}
// print_r($scenic);

$thumb = $scenic['thumb_path'] ? $scenic['thumb_path']:'prodimgs/123642/20140916/14108485792643.jpg';
$video = $scenic['video_path'] ? $scenic['video_path']:'';
$voice = $scenic['intro_voice_path'] ? $scenic['intro_voice_path']:'';
$panorama = $scenic['degree_path'] ? $scenic['degree_path']:'';


// 父景点ID 即 uu_land 表 id
$parent_id = $_REQUEST['lid'] ? $_REQUEST['lid']:$scenic['lid'];
// if(empty($parent_id)) exit('非法访问');

$page_title = "产品发布 - ";
?>
<script>document.domian="12301.cc";</script>
<link rel="stylesheet" href="http://www.12301.cc/css/aliceui.min.css"/>
<link rel="stylesheet" href="http://www.12301.cc/css/resetui.css"/>
<link rel="stylesheet" href="http://www.12301.cc/css/prod_store.css"/>
<script language="javascript" src="http://www.12301.cc/js/jquery-1.8.0.min.js"></script>
<script src="http://www.12301.cc/js/WdatePicker.js"></script>
<div class="wrapper">
<h3 class="mc_title">
	<span class="mctit_1"><span class="mctit_2">营销活动发布</span></span>
</h3>
<?if(!$isedit||isset($_GET['step'])){?>

<?}?>

	
<div id="sceneryBox" class="ui-box mt10 fn-clear">
<?if($isedit){?>
<div class="ui-box-head">
	<h3 class="ui-box-head-title"><?=$ProdTypes[$ptype]?>信息</h3>
	<span class="ui-box-head-text"></span>
	<a href="#" class="ui-box-head-more"></a>
</div>
<?}?>
<div class="ui-box-container">
	<div class="ui-box-content">
						<form name="mainForm" id="mainForm" class="ui-form" method="post" action="../common/upload_discount.php" enctype="multipart/form-data" target="hideFrame">
						<input type="hidden" name="lastid" value="<?=$scenic['id']?>"/>
						<input type="hidden" name="parent_id" value="<?=$parent_id?>"/>  
						<input type="hidden" name="applydid" value="<?=$apply_did?>"/>
						<input type="hidden" name="action" value="scenic"/>
						<input type="hidden" name="upload_mth" id="upload_mth" value="1"/> 
						<fieldset>
							<div class="ui-form-item">
								<label class="ui-label"><span class="ui-form-required">*</span>活动名称</label>
								<input title="请填写活动名称" class="ui-input check w408" data-required="2" id="mainTitle" name="mainTitle" type="text"  value="" />
								<span class="ui-form-other ui-form-explain">请填写活动名称</span>
							</div>
							<div class="ui-form-item">
								<label class="ui-label"><span class="ui-form-required">*</span>活动时间</label>
								<input type="text" data-t="bt" class="ui-input_msg_t" id="txtStartTime" data-msg="请选择时间段" value=""  name="order_start" class="required input-text w66"  /> 至
								<input type="text" data-t="bt" class="ui-input_msg_t" id="txtEndTime" data-msg="请选择时间段" value=""  name="order_end" class="required input-text w66"  />	
							</div>
							
							<div class="land ui-form-item">
								<label class="ui-label"><span class="ui-form-required">*</span>活动类型</label>
								<select name="discount_type" size="1" class="dis_select" onChange="change()" id="goods_style"> 
									<option value="0" selected="selected">秒杀</option> 
									<option value="1">限量打折</option> 
									<option value="2">分享立减</option>  
								</select>
								<div class="d_money">
									<span id="dropmsg">减现金&nbsp;<input name="down_money" class="ui-input_msg">&nbsp;元</span>
									<span id="dropmsg_a">总金额打&nbsp;<input name="discount_money" class="ui-input_msg" >&nbsp;折</span>
								</div>
							</div>	
							<div class="ui-form-item" id="dropmsg_c">
								<label class="ui-label">
									<span class="ui-form-required" >*</span>分享网页
								</label>
								<input title="" class="ui-input check w408" data-required="2"  name="show_html" type="text" value="" />
							</div>
							<div class="ui-form-item"> 
								<label class="ui-label">
									<span class="ui-form-required">*</span>单用户限购
								</label>
								<input name="limit_num" class="ui-input_msg_num">
							</div>		
							<input type="hidden" name="showimgPathInp" id="showimgPathInp"/>
						</fieldset>
					</form>
						<form id="imgUpload_form" action="http://s.12301.cc/pft/marketing/marketing.php" method="post" enctype="multipart/form-data" target="hideFrame">
							<div class="ui-form-item" style="position: relative;">
								<input name="auth" value="upload" type="hidden"/>
								<input name="imgUpload_fileVal" value="upload" type="hidden"/>
								<input name="action" value="upload" type="hidden"/>
								<label class="ui-label"><span class="ui-form-required">*</span>活动图片</label>
								<a class="lnk_prv" target="_blank" title="点击查看原图" href="<?=$thumb?>">
									<!-- <input type="hidden" name="thumb_img" class="thumb_img" value="<?=$thumb?>"/> -->
									<!-- <input type="hidden" name="" id="showimgPathInp"/> -->
									<img style="width:240px;height:160px;" src="<?=$thumb?>" id="discount_img" class="preview" onerror="javascript:this.src='http://www.12301.cc/images/defaultThum.jpg'" />
								</a>
								<div class="uploadImg">
									<p class="title">重新上传缩略图：</p>
									<input type="file" id="imgUpload_inpFile" name="image"/>
									<input type="button" id="submitImgUploadBtn" value="上传" class="ui-button ui-button-swhite"/>
									<p class="ui-form-explain">点击上传小于1M的JPG或GIF格式的图片,<br/>建议图片尺寸：宽350像素，高230像素</p>
									<p class="waitingUpload" class="ui-form-other"></p>
									<div id="uploadResultCon"></div>
									<div id="uploadFailTip"></div>
								</div>
							</div>
						</form>
						<div class="ui-form-item"><button class="ui-button ui-button-lblue" id="saveProduct" data-wrap="ticketBox" type="button">保存，返回列表</button></div>
				</div>
			</div>
		</div>
</div><!--div.wrapper-->
<iframe src="about:blank" style="display: none;" id="hideFrame" name="hideFrame" frameborder="0"></iframe>

<!-- <script>
//结束时间不得早于开始时间
$("#txtStartTime").bind("click focus", function () {             
   var endtimeTf = $dp.$('txtEndTime');             
   WdatePicker({                            
	   maxDate: '#F{$dp.$D(\'txtStartTime\')}',      
	   dateFmt: "yyyy-MM-dd HH:mm:ss",              
	   onpicked: function () { endtimeTf.focus(); }          
		});         
   });          
   $("#txtEndTime").bind("click focus", function () {       
		WdatePicker({           
		   minDate: '#F{$dp.$D(\'txtStartTime\')}', 
		   dateFmt: "yyyy-MM-dd HH:mm:ss"       
	   });         
   });
//选择隐藏
    $("#dropmsg_a").hide();
	$("#dropmsg_c").hide(); 	
	$("#dropmsg").show(); 
	function change(){ 
		if($("#goods_style").attr("value")=='1'){ 
			$("#dropmsg_a").show(); 
			$("#dropmsg").hide(); 
			$("#dropmsg_c").hide(); 
		}else{ 
			if($("#goods_style").attr("value")=='2'){ 
				$("#dropmsg_c").show(); 
			}
			else{
			 $("#dropmsg_c").hide(); 
			}
			$("#dropmsg_a").hide(); 
			$("#dropmsg").show(); 
		} 
	} 

 $("#submitImgUploadBtn").on("click",function(e){
        //var active = $("#imgDialog-tabNavCon").children(".active");
        ImgUpload.upload();

    })
    $("#imgUpload_inpFile").on("change",function(e){
        ImgUpload.onFileChange(e.currentTarget);
    })
    var ImgUpload = (function(){

        function onFileChange(inpFile){
            var path = inpFile.value;
            path = path.replace(/c:\\fakepath\\/gi,"");
            path.replace(/c:/ig,"");
            $("#imgUpload_fileVal").val(path);
        }
        function upload(){
            // $("#image-container").hide();
            onloading();
            $("#imgUpload_form").submit();
        }
        function onloading(){
            var imgname = $("#imgUpload_fileVal").val();
            var loadingImg = "http://www.12301.cc/images/other/loading_1.gif";
            var html = '<div class="uploadResult loading"><div class="con"><img src="'+loadingImg+'"/><span class="text">正在上传图片...</span></div></div>';
            $("#uploadFailTip").hide();
            $("#uploadResultCon").html(html);
        }
        function onload(data){ //上传图片完成
            console && console.log("上传图片完成，未知是否成功");
            if(data.status == "ok" && data.key){
                console && console.log("上传图片成功");
                onSuccess(data);
            }else{
                console && console.log("上传图片失败");
                onFail(data)
            }
        }
        function onSuccess(data){
            var path = data.key;
            //var html = '<div class="ui-form-item"><div class="lnk_prv"><img src="'+path+'"/></div></div>';
            //$("#uploadResultCon").html(html);
			$("#discount_img").attr('src',path);
            $("#showimgPathInp").val(path);
			$("#uploadResultCon").hide();
            WXB.G.Alert("success",'<p style="width:150px;">上传图片成功</p>',2000)
        }
        function onFail(data){
            var img = '<img src="http://www.12301.cc/wx_public/images/nopic.jpg"  class="img-responsive img-thumbnail" width="150">';
            $("#uploadResultCon").html(img);
            $("#uploadFailTip").show();
            WXB.G.Alert("fail",'<p style="width:150px;">上传图片失败</p>')
        }
        return{
            onFileChange : onFileChange,
            upload : upload,
            onload : onload
        }

    })();
</script> -->
<iframe src="about:blank" style="display: block;" id="hideFrame" name="hideFrame" frameborder="0"></iframe>
<script type="text/javascript" src="http://www.12301.cc/js/easydialog.min.js" ></script>
<script type="text/javascript" src="http://www.12301.cc/js/prod_pub.js"></script>
<script type="text/javascript" src="http://www.12301.cc/js/prod_editk_discount.js?body=1"></script>
<script type="text/javascript" src="http://www.12301.cc/js/discount_img.js"></script>
